#pragma once
#include "MarkerMgr.h"

class StatusMgr : protected IEntityMgr {
public:
	static auto get() {
		static auto instance = new StatusMgr;
		return instance;
	}

	/**@brief called per frame, at rendering thread */
	void updateEntities() override {
		if (IsProject_SQ || AsPretendedProject_SQ) {
			updateSQStatus();
			return;
		}
		MarkerMgr::get()->update(MarkerType::DCLC);
		MarkerMgr::get()->update(MarkerType::ALC);
		MarkerMgr::get()->update(MarkerType::LDW);
		MarkerMgr::get()->update(MarkerType::ACC_TG);
		MarkerMgr::get()->update(MarkerType::TailLamp);
	}

	void clear() override {
		if (IsProject_SQ || AsPretendedProject_SQ) {
			clearSQStatus(false);
			return;
		}
		Cache::clearStatus();
		updateEntities();
	}

private:
	StatusMgr() = default;

	/******************************* SQ-Android *******************************/
	/******************************* SQ-Android *******************************/

	void clearSQStatus(bool clearGlobalCache = true) {// keep the cached values, for crash auto restart sake
		if (clearGlobalCache)
			Cache::clearSQStatus();
		MarkerMgr::get()->remove(MarkerType::SQ_ALC);
		MarkerMgr::get()->remove(MarkerType::DCLC);
	}

	void updateSQStatus() {
		const auto& status = Cache::sqStatus();
		sq::ALC alc = status.alc;// priority higher than NOA
		DCLC dclc = DCLC::Off;

		if (alc == sq::ALC::Left) dclc = DCLC::ToLeft;
		else if (alc == sq::ALC::Right) dclc = DCLC::ToRight;
		else if (status.noa == sq::NOA::On) dclc = DCLC::Mid;

		MarkerMgr::get()->update(MarkerType::SQ_ALC);
		MarkerMgr::get()->update(MarkerType::DCLC);
	}
};